package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.common.MessageConst;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.service.CheckGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/checkGroup")
public class CheckGroupController {

    @Reference
    private CheckGroupService checkGroupService;

    @RequestMapping("/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        log.debug("获得了检查组查询参数+++++"+queryPageBean);
        PageResult pageResult = checkGroupService.findPage(queryPageBean);
        log.debug("查询出的数据为+++++++"+pageResult);
        return new Result(true, MessageConst.QUERY_CHECKGROUP_SUCCESS,pageResult);
    }

    @RequestMapping("/add")
    public Result add(Integer[] ids,@RequestBody CheckGroup checkGroup){
        checkGroupService.add(checkGroup,ids);
        return new Result(true,MessageConst.ADD_CHECKGROUP_SUCCESS);
    }


    @RequestMapping("/findById")
    public Result findById(Integer id){
      CheckGroup checkGroup = checkGroupService.findById(id);
      return new Result(true,MessageConst.QUERY_CHECKGROUP_SUCCESS,checkGroup);
    }

    @RequestMapping("/findCheckitemById")
    public Result findCheckitemById(Integer id){
        Integer[] ids = checkGroupService.findCheckitemById(id);
        return new Result(true,MessageConst.QUERY_CHECKITEM_SUCCESS,ids);
    }

    @RequestMapping("/edit")
    public Result edit(Integer[] ids,@RequestBody CheckGroup checkGroup){
        checkGroupService.edit(ids,checkGroup);
        return new Result(true,MessageConst.EDIT_CHECKGROUP_SUCCESS);
    }

    @RequestMapping("/delById")
    public Result delById(Integer id){
        checkGroupService.delById(id);
        return new Result(true,MessageConst.DELETE_CHECKGROUP_SUCCESS);
    }

    @RequestMapping("/findAll")
    public Result findAll(){
        List all = checkGroupService.findAll();
        return new Result(true,MessageConst.QUERY_CHECKGROUP_SUCCESS,all);
    }

}
